//
//  YXJPushMusicCell.m
//  Piece
//
//  Created by dllo on 16/6/22.
//  Copyright © 2016年 Northeast Dianli University. All rights reserved.
//

#import "YXJPushMusicCell.h"
#import "NSString+YXJHeight.h"
#import "UIImageView+WebCache.h"

@implementation YXJPushMusicCell
-(instancetype)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier
{
    self = [super initWithStyle:style reuseIdentifier:reuseIdentifier];
    if (self) {
        
        //初始化headView
        self.headView = [[UIView alloc] initWithFrame:CGRectMake(-30, 0, ScreenWidth, ScreenHeight - 143)];
        [self.contentView addSubview: _headView];
        
        //初始化歌曲背景图片
        self.photoImageView = [[UIImageView alloc] init];
        [self.headView addSubview:_photoImageView];
        
        //初始化歌曲信息view
        self.detailView = [[YXJView alloc] init];
        self.contentView.backgroundColor = [UIColor whiteColor];
        self.contentView.layer.borderWidth = 2;
        self.contentView.layer.borderColor = [UIColor colorWithRed:0.87 green:0.87 blue:0.88 alpha:1.00].CGColor;
        [self.headView addSubview:_detailView];
        
        //初始化音乐故事
        self.musicStoryLabel = [[UILabel alloc] init];
        self.musicStoryLabel.text = @"背景故事";
        [self.musicStoryLabel setTextColor:[UIColor colorWithRed:0.73 green:0.73 blue:0.74 alpha:1.00]];
        self.musicStoryLabel.font = [UIFont systemFontOfSize:13];
        [self.headView addSubview:_musicStoryLabel];
        
        //初始化歌词按钮
        self.lyricButton = [UIButton buttonWithType:UIButtonTypeCustom];
        [_lyricButton addTarget:self action:@selector(didLyricButton:) forControlEvents:UIControlEventTouchUpInside];
        [_lyricButton setImage:[UIImage imageNamed:@"music_lyric_normal"] forState:UIControlStateNormal];
        _lyricButton.tag = 1002;
        [self.headView addSubview:_lyricButton];
        
        
        //初始化歌曲信息按钮
        self.aboutButton = [UIButton buttonWithType:UIButtonTypeCustom];
        [_aboutButton addTarget:self action:@selector(didAboutButton:) forControlEvents:UIControlEventTouchUpInside];
        [_aboutButton setImage:[UIImage imageNamed:@"music_about_normal"] forState:UIControlStateNormal];
        _aboutButton.tag = 1003;
        [self.headView addSubview:_aboutButton];

        
        }
    return self;
}

- (void)layoutSubviews
{
    [super layoutSubviews];
    self.photoImageView.frame = CGRectMake(0, 0, ScreenWidth, ScreenWidth);
    self.contentView.frame = CGRectMake(10, ScreenWidth - 15, ScreenWidth - 20, 110);
    self.musicStoryLabel.frame = CGRectMake(_detailView.frame.origin.x, ScreenWidth + _detailView.frame.size.height, 100, 20);
    self.lyricButton.frame = CGRectMake(ScreenWidth - 105, _musicStoryLabel.frame.origin.y - 10, 44, 44);
    self.aboutButton.frame = CGRectMake(ScreenWidth - 50, _musicStoryLabel.frame.origin.y - 10, 44, 44);
}

- (void)didLyricButton:(UIButton *)sender
{
    self.musicStoryLabel.text = @"歌词";
    [sender setImage:[UIImage imageNamed:@"music_lyric_selected"] forState:UIControlStateNormal];
//    [_storyButton setImage:[UIImage imageNamed:@"music_story_normal"] forState:UIControlStateNormal];
    [_aboutButton setImage:[UIImage imageNamed:@"music_about_normal"] forState:UIControlStateNormal];
//    self.whichPage = 2;
//    [self.tableView reloadData];
}

- (void)didAboutButton:(UIButton *)sender
{
    self.musicStoryLabel.text = @"相关信息";
    [sender setImage:[UIImage imageNamed:@"music_about_selected"] forState:UIControlStateNormal];
//    [_storyButton setImage:[UIImage imageNamed:@"music_story_normal"] forState:UIControlStateNormal];
    [_lyricButton setImage:[UIImage imageNamed:@"music_lyric_normal"] forState:UIControlStateNormal];
//    self.whichPage = 3;
//    [self.tableView reloadData];
}

- (void)setModel:(YXJMusicModel *)model
{
    if (_model != model) {
        _model = model;
        
//        [self. sd_setImageWithURL:[NSURL URLWithString:model.cover]];
        [self.detailView.userImageView sd_setImageWithURL:[NSURL URLWithString:model.authorModel.web_url] placeholderImage:[UIImage imageNamed:@"personal"]];
        self.detailView.realName.text = model.authorModel.user_name;
        self.detailView.nickName.text = model.authorModel.desc;
        self.detailView.musicName.text = model.title;
//        self.detailView.dateLabel.text = [self changeFormString:model.maketime];
    }
}


@end
